import request from '@/components/hzjc/utils/request.js'

let mall = {}

/**
 * 获取分类
 * @date 2022-10-27
 */
mall.listCategory = function() {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Product/listCategory', {}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取商品列表
 * @param {object} that
 * @param {int} isFirstPage 是否第一页 0--不是 1--是
 * @param {int} firstCategoryId 一级分类ID
 * @param {int} secondCategoryId 二级分类ID
 * @param {int} keyword 关键词
 * @param {int} isRecommend 是否推荐 0--不限制 1--是推荐
 * @param {int} priceMin 最低价钱
 * @param {int} priceMax 最高价钱
 * @param {int} order 排序
 * @date 2022-10-27
 */
mall.listProduct = function(that, isFirstPage, firstCategoryId, secondCategoryId, keyword, isRecommend, priceMin,
	priceMax, order) {

	return new Promise((resolve, reject) => {
		let data = {}

		data.first_category_id = firstCategoryId
		data.second_category_id = secondCategoryId
		data.keyword = keyword
		data.is_recommend = isRecommend
		data.price_min = priceMin
		data.price_max = priceMax
		data.order = order

		request.getList('mall/api/Product/listProduct', data, {
			that: that,
			first_page: isFirstPage
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取商品详情
 * @param {int} productId 产品ID
 * @date 2022-12-13
 */
mall.getProduct = function(productId) {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Product/getProduct', {
			product_id: productId
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 购物车
 */
mall.cart = {
	/**
	 * 加载购物车产品列表
	 * @date 2023-02-01
	 */
	listCartProduct: function() {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Cart/listCartProduct').then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 加入或更新购物车
	 * @param {int} productId 产品ID
	 * @param {string} productSku 产品SKU
	 * @param {int} number 购买数量
	 * @param {int} isSelect 是否选中 0--未选中 1--已选中
	 * @date 2023-01-31
	 */
	updateCartProduct: function(productId, productSku, number, isSelect = 0) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Cart/updateCartProduct', {
				product_id: productId,
				product_sku: productSku,
				number: number,
				is_select: isSelect
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 更新购物车产品数量
	 * @param {int} cartId 购物车ID
	 * @param {int} type 类型 
	 * @param {int} number type=3时，购买数量
	 * @date 2023-01-31
	 */
	updateCartProductNumber: function(cartId, type, number) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Cart/updateCartProductNumber', {
				cart_id: cartId,
				type: type,
				number: number
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 购物车产品选中/取消选中
	 * @param {int} cartId 购物车ID
	 * @param {int} isSelect 是否选中
	 * @date 2023-01-31
	 */
	updateCartProductSelectedStatus: function(cartId, isSelect) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Cart/updateCartProductSelectedStatus', {
				cart_id: cartId,
				is_select: isSelect
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 购物车产品全部选中/全部取消选中
	 * @param {int} isSelect  是否选中
	 * @date 2023-01-31
	 */
	updateAllCartProductSelectedStatus: function(isSelect) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Cart/updateAllCartProductSelectedStatus', {
				is_select: isSelect
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 删除选中宝贝
	 * @date 2023-02-01
	 */
	deleteCartSelectedProduct: function() {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Cart/deleteCartSelectedProduct').then(res => {
				resolve(res)
			}, {
				loading: true
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 清空失效宝贝
	 * @date 2023-02-01
	 */
	deleteCartInvalidProduct: function() {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Cart/deleteCartInvalidProduct').then(res => {
				resolve(res)
			}, {
				loading: true
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取购物车种类数量
	 * @date 2023-01-31
	 */
	countCartTypeNumber: function() {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Cart/countCartTypeNumber').then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取凑单价钱区间及当前选中
	 * @param {float} differMoney 差X元免运费
	 * @date 2023-01-31
	 */
	listPool: function(differMoney) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Cart/listPool', {
				differ_money: differMoney
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	}
}

/**
 * 订单
 */
mall.order = {
	/**
	 * 获取下单数据
	 * @param {int} type 下单类型 1--商城 2--秒杀商城
	 * @param {int} buyType 购买类型 1--购物车 2--立即购买
	 * @param {int} myAddressId 我的地址ID
	 * @param {int} productId buyType=2时，产品ID
	 * @param {string} productSku buyType=2时，产品SKU
	 * @param {int} number buyType=2时，购买数量
	 * @param {int} isChooseDefaultCoupon 是否选择默认的最大可选优惠券
	 * @param {int} myCouponId 我的优惠券ID
	 * @param {int} spikeProductId type=2时，秒杀商品ID
	 * @date 2022-10-13
	 */
	getOrderReady: function(type, buyType, myAddressId, productId, productSku, number, isChooseDefaultCoupon,
		myCouponId, spikeProductId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/getOrderReady', {
				buy_type: buyType,
				my_address_id: myAddressId,
				product_id: productId,
				product_sku: productSku,
				number: number,
				is_choose_default_coupon: isChooseDefaultCoupon,
				my_coupon_id: myCouponId,
				type: type,
				spike_product_id: spikeProductId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 提交订单并支付
	 * @param {int} type 下单类型 1--商城 2--秒杀商城
	 * @param {int} buyType 购买类型 1--购物车 2--立即购买
	 * @param {int} myAddressId 我的地址ID
	 * @param {int} productId buyType=2时，产品ID
	 * @param {string} productSku buyType=2时，产品SKU
	 * @param {int} number buyType=2时，购买数量
	 * @param {int} myCouponId 我的优惠券ID
	 * @param {int} payType 支付方式 1--微信支付 2--支付宝支付 3--余额支付
	 * @param {string} remark 备注
	 * @param {int} spikeProductId type=2时，秒杀商品ID
	 * @date 2022-10-31
	 */
	insertOrder: function(type, buyType, myAddressId, productId, productSku, number,
		myCouponId, payType, remark, spikeProductId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/insertOrder', {
				buy_type: buyType,
				my_address_id: myAddressId,
				product_id: productId,
				product_sku: productSku,
				number: number,
				my_coupon_id: myCouponId,
				pay_type: payType,
				remark: remark,
				type: type,
				spike_product_id: spikeProductId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取我的订单列表
	 * @param {object} that
	 * @param {int} isFirstPage 是否第一页 0--不是 1--是
	 * @param {int} index 订单状态 0--所有 1--待支付 2--待发货 3--待收货 4--已完成
	 * @param {string} keyword 关键字
	 * @date 2023-02-01
	 */
	listMyOrder: function(that, isFirstPage, index, keyword) {
		return new Promise((resolve, reject) => {
			request.getListByLastId('mall/api/Order/listMyOrder', {
				index: index,
				keyword: keyword
			}, {
				that: that,
				first_page: isFirstPage
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取我的订单详情
	 * @param {int} orderId 订单ID
	 * @date 2023-02-01
	 */
	getMyOrder: function(orderId, isCheckUser = 1) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/getMyOrder', {
				order_id: orderId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取订单数量
	 * @date 2022-12-28
	 */
	countOrderNumber: function() {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/countOrderNumber').then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},



	/**
	 * 再支付订单
	 * @param {int} orderId 订单ID
	 * @param {int} payType 支付方式 1--微信支付 2--支付宝支付 3--余额支付
	 * @date 2022-10-31
	 */
	rePayOrder: function(orderId, payType) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/rePayOrder', {
				order_id: orderId,
				pay_type: payType
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},


	/**
	 * 取消订单
	 * @param {int} orderId 订单ID
	 * @date 2022-10-31
	 */
	cancelOrder: function(orderId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/cancelOrder', {
				order_id: orderId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 订单提醒发货
	 * @param {int} orderId 订单ID
	 * @date 2023-02-01
	 */
	remindOrder: function(orderId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/remindOrder', {
				order_id: orderId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},


	/**
	 * 确认收货订单
	 * @param {int} orderId 订单ID
	 * @date 2023-02-01
	 */
	finishOrder: function(orderId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/finishOrder', {
				order_id: orderId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},


	/**
	 * 删除订单
	 * @param {int} orderId 订单ID
	 * @date 2023-02-02
	 */
	deleteOrder: function(orderId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/deleteOrder', {
				order_id: orderId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 查询物流
	 * @param {int} orderId 订单ID
	 * @date 2023-02-02
	 */
	getLogistics: function(orderId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/getLogistics', {
				order_id: orderId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 再次购买
	 * @param {int} orderId 订单ID
	 * @date 2023-02-02
	 */
	reBuyOrder: function(orderId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Order/reBuyOrder', {
				order_id: orderId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},
}

mall.refund = {

	/**
	 * 获取退款记录列表
	 * @param {object} that
	 * @param {int} isFirstPage 是否第一页 0--不是 1--是
	 * @date 2023-02-24
	 */
	listRefundOrder: function(that, isFirstPage) {
		return new Promise((resolve, reject) => {
			request.getList('mall/api/Refund/listRefundOrder', {}, {
				that: that,
				first_page: isFirstPage
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取退款产品
	 * @param {int} orderProductId 订单产品ID
	 * @date 2023-02-02
	 */
	getRefundProduct: function(orderProductId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Refund/getRefundProduct', {
				order_product_id: orderProductId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取退款金额
	 * @param {int} orderProductId 订单产品ID
	 * @param {int} number 退款数量
	 * @date 2023-02-02
	 */
	getOrderRefundMoney: function(orderProductId, number) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Refund/getOrderRefundMoney', {
				order_product_id: orderProductId,
				number: number
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 订单退款
	 * @param {int} orderProductId 订单产品ID
	 * @param {int} number 退款数量
	 * @param {int} refundId 退款原因ID
	 * @param {array} refundImages 退款图片
	 * @param {string} remark 退款说明
	 * @date 2023-02-02
	 */
	insertOrderRefund: function(orderProductId, number, refundId, refundImages, remark) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Refund/insertOrderRefund', {
				order_product_id: orderProductId,
				number: number,
				refund_id: refundId,
				refund_images: refundImages,
				remark: remark
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取订单产品退款列表
	 * @param {int} orderProductId 订单产品ID
	 * @date 2023-02-02
	 */
	listOrderProductRefund: function(orderProductId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Refund/listOrderProductRefund', {
				order_product_id: orderProductId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取退款订单详情
	 * @param {int} refundOrderId 退款订单ID
	 * @date 2023-02-02
	 */
	getRefund: function(refundOrderId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Refund/getRefund', {
				refund_order_id: refundOrderId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 订单退款取消
	 * @param {int} refundId 退款订单ID
	 * @date 2023-02-24
	 */
	cancelRefundOrder: function(refundId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Refund/cancelRefundOrder', {
				refund_id: refundId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 订单删除
	 * @param {int} refundId 订单产品ID
	 * @date 2023-02-24
	 */
	deleteRefundOrder: function(refundId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Refund/deleteRefundOrder', {
				refund_id: refundId
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},
}

/**
 * 评价
 */
mall.evaluate = {
	/**
	 * 新增商品评价
	 * @param {int} orderId 订单ID
	 * @param {array} orderProduct 订单产品评论数据
	 * @date 2023-02-01
	 */
	insertEvaluate: function(orderId, orderProduct) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Evaluate/insertEvaluate', {
				order_id: orderId,
				order_product: orderProduct
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 新增商品追加评价
	 * @param {int} orderId 订单ID
	 * @param {array} orderProduct 订单产品评论数据
	 * @date 2023-02-01
	 */
	insertAppendEvaluate: function(orderId, orderProduct) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Evaluate/insertAppendEvaluate', {
				order_id: orderId,
				order_product: orderProduct
			}, {
				loading: true
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取商品评价列表
	 * @param {object} that
	 * @param {int} isFirstPage 是否第一页 0--不是 1--是
	 * @param {int} productId 产品ID
	 * @param {int} index 评论类型 0--全部 1--有图 2--好评 3--中评 4--差评 5--追评
	 * @date 2023-02-01
	 */
	listEvaluate: function(that, isFirstPage, productId, index) {
		return new Promise((resolve, reject) => {
			request.getList('mall/api/Evaluate/listEvaluate', {
				product_id: productId,
				index: index
			}, {
				that: that,
				first_page: isFirstPage
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取商品评价列表
	 * @param {int} productId 产品ID
	 * @date 2023-02-09
	 */
	listOneEvaluate: function(productId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Evaluate/listOneEvaluate', {
				product_id: productId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取我的评价列表
	 * @param {object} that
	 * @param {int} isFirstPage 是否第一页 0--不是 1--是
	 * @date 2023-02-01
	 */
	listMyEvaluate: function(that, isFirstPage) {
		return new Promise((resolve, reject) => {
			request.getList('mall/api/Evaluate/listMyEvaluate', {}, {
				that: that,
				first_page: isFirstPage
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取商品评价种类数量
	 * @param {int} productId 产品ID
	 * @date 2023-02-01
	 */
	countEvaluateNumber: function(productId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Evaluate/countEvaluateNumber', {
				product_id: productId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},
}

mall.spike = {
	/**
	 * 获取秒杀商品详情
	 * @param {int} productId 产品ID
	 * @date 2023-02-15
	 */
	getProduct: function(productId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Spike/getProduct', {
				product_id: productId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取场次列表
	 * @date 2023-02-16
	 */
	listScene: function() {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Spike/listScene').then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取我的浏览记录
	 * @param {object} that
	 * @param {int} isFirstPage 是否第一页 0--不是 1--是
	 * @param {string} sTime 开始时间
	 * @param {string} eTime 结束时间
	 * @date 2022-11-30
	 */
	listSceneProduct: function(that, isFirstPage, sTime, eTime) {
		return new Promise((resolve, reject) => {
			request.getList('mall/api/Spike/listSceneProduct', {
				s_time: sTime,
				e_time: eTime
			}, {
				that: that,
				first_page: isFirstPage
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 插入秒杀提醒
	 * @param {int} spikeId 秒杀ID
	 * @date 2023-02-17
	 */
	insertNotice: function(spikeId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/SpikeNotice/insertNotice', {
				spike_id: spikeId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 取消秒杀提醒
	 * @param {int} spikeId 秒杀ID
	 * @date 2023-02-17
	 */
	cancelNotice: function(spikeId) {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/SpikeNotice/cancelNotice', {
				spike_id: spikeId
			}).then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},
}

/**
 * 插入浏览记录
 * @param {int} productId 产品ID
 * @date 2023-01-30
 */
mall.insertBrowse = function(productId) {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Browse/insertBrowse', {
			product_id: productId
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取我的浏览记录
 * @param {object} that
 * @param {int} isFirstPage 是否第一页 0--不是 1--是
 * @date 2022-11-30
 */
mall.listMyBrowse = function(that, isFirstPage) {
	return new Promise((resolve, reject) => {
		request.getList('mall/api/Browse/listMyBrowse', {}, {
			that: that,
			first_page: isFirstPage
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 删除我的浏览记录
 * @param {string} browseIds 需要删除的浏览记录ID
 * @date 2022-12-01
 */
mall.deleteMyBrowse = function(browseIds) {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Browse/deleteMyBrowse', {
			browse_ids: browseIds
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 删除全部我的浏览记录
 * @date 2022-12-01
 */
mall.deleteAllMyBrowse = function(browseIds) {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Browse/deleteAllMyBrowse').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 产品收藏/取消收藏
 * @param {int} productId 产品ID
 * @param {int} collectType 收藏操作 0--取消收藏  1--收藏
 * @date 2023-01-30
 */
mall.updateCollect = function(productId, collectType) {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Collect/updateCollect', {
			product_id: productId,
			collect_type: collectType
		}, {
			loading: true
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取我的收藏记录
 * @param {string} keyword 关键字
 * @date 2022-12-01
 */
mall.listMyCollect = function(keyword) {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Collect/listMyCollect', {
			keyword: keyword
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 多选删除我的收藏列表
 * @param {array} collectIds 需要删除的收藏记录ID
 * @date 2022-12-01
 */
mall.deleteMyCollect = function(collectIds) {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Collect/deleteMyCollect', {
			collect_ids: collectIds
		}, {
			loading: true
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 是否收藏
 * @param {int} productId 产品ID
 * @date 2023-01-30
 */
mall.isCollect = function(productId) {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Collect/isCollect', {
			product_id: productId
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取轮播图
 * @date 2022-10-27
 */
mall.getCarousel = function() {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Config/getCarousel').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取广告图
 * @date 2022-10-27
 */
mall.getAdvertise = function() {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Config/getAdvertise').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

// 设置
mall.config = {
	/**
	 * 获取包邮运费
	 * @date 2023-01-31
	 */
	getFreeFreight: function() {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Config/getFreeFreight').then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	},

	/**
	 * 获取秒杀设置
	 * @date 2023-02-16
	 */
	getSpikeConfig: function() {
		return new Promise((resolve, reject) => {
			request.getData('mall/api/Config/getSpikeConfig').then(res => {
				resolve(res)
			}).catch(res => {
				reject(res)
			})
		})
	}
}

/**
 * 获取商城客服手机号
 * @date 2023-01-31
 */
mall.getLinkTel = function() {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Config/getLinkTel').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取退款原因
 * @date 2023-01-31
 */
mall.listRefundCause = function() {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Config/listRefundCause').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取热门搜索
 * @date 2022-11-17
 */
mall.listHotSearch = function() {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Search/listHotSearch').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 获取历史搜索
 * @date 2022-11-17
 */
mall.listHistorySearch = function() {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Search/listHistorySearch').then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 添加历史搜索
 * @param {string} keyword 关键字
 * @date 2022-11-17
 */
mall.insertHistorySearch = function(keyword) {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Search/insertHistorySearch', {
			keyword: keyword
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

/**
 * 清空历史搜索
 * @date 2022-11-17
 */
mall.deleteAllHistorySearch = function(keyword) {
	return new Promise((resolve, reject) => {
		request.getData('mall/api/Search/deleteAllHistorySearch', {
			keyword: keyword
		}).then(res => {
			resolve(res)
		}).catch(res => {
			reject(res)
		})
	})
}

export default mall
